<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
  </head>
  <body>
    <script type="text/javascript">
     function Node(num)
  {
       this.num   = num;
   this.count = 1;
    this.pLeft = null;
       this.pRight = null;
   }


  function createNode(value)
  {
      var pNode      = new Node(value);
      pNode.num    = value;
      pNode.count  = 1;
      pNode.pLeft  = null;
      pNode.pRight = null;
      return pNode;
 }


  function  addNode(value, pNode)
  {
      if (pNode == null){
          return createNode(value);
     }
      if (value == pNode.num){
          pNode.count++;
          return pNode;
      }
      if (value < pNode.num){
          if (pNode.pLeft == null){
              pNode.pLeft = createNode(value);
                           return pNode.pLeft;
          }else{
              return addNode(value, pNode.pLeft);
          }
      }else{
         if (pNode.pRight == null){
             pNode.pRight = createNode(value);
             return pNode.pRight;
        }else{
            return addNode(value, pNode.pRight);
         }
      }
  }

  var list = [10,8,15,2,14,16,20,7,5,13,60,34,1,10];
  var pRoot = null;
  var lent = list.length;
 for(var i=0; i<lent; i++){

    if (pRoot==null){
          pRoot = createNode(list[i]);
    }else{
         addNode(list[i], pRoot);
    }
 }
 console.info(pRoot);
 </script>
  </body>
</html>
